<script type="text/javascript" src="./libraries/dat.gui.min.js"></script>
<script type="text/javascript" src="./libraries/plotly-basic.min.js"></script>
<script type="text/javascript" src="./libraries/tf.min.js"></script>
<script type="text/javascript" src="./SimpleBCI.js"></script>
<link rel="stylesheet" type="text/css" href="./main.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<body>
	<div><input id="ipInput" type="text" 
		value="192.168.2.119" onchange="connect()"/></div>
	<div id="signalPlot"></div>
	<div id="filteredPlot"></div>
	<div id="dftPlot"></div>
	<!--div><textarea id="message"></textarea></div-->
	<div id="guiDiv"></div>
</body>

<script type="text/javascript">
const simpleBCI = new SimpleBCI({34:0,33:1})
try{connect()}catch{}

function connect(){
	console.log("trying to connect!")
	var ip=document.querySelector("#ipInput").value
	console.log(ip)
	connection = new WebSocket('ws://'+ip+":81")//,['arduino'])
	connection.onopen=()=>{simpleBCI.connection=connection;console.log("opened")}
	connection.onmessage=(event)=>{simpleBCI.onMessage(event.data)
		//var message=document.querySelector("#message")
		//nLines = message.value.match(/\n/g);  if(nLines && nLines.length>12) message.value=''
		//message.value+=(event.data+"\n")
	}
	connection.onclose=()=>{console.log("closed");connect()}
	connection.onerror=()=>{console.log("error");connect()}
}
</script>
